using UnityEngine;

public class IntroAttribute : MonoBehaviour
{
	public class Property
	{
		public float propertyValue;

		public UISprite fillSprite;

		public void UpdateFillSprite(float delta)
		{
			fillSprite.fillAmount = Mathf.Lerp(fillSprite.fillAmount, propertyValue, delta);
		}
	}

	public UILabel nameLabel;

	public UISprite leftFill;

	public UISprite rightFill;

	public Color minColor;

	public Color maxColor;

	public PlayerStatsManager.SkillType skillType;

	protected float speed = 5f;

	protected Property leftProperty;

	protected Property rightProperty;

	private void Awake()
	{
		nameLabel.text = string.Empty;
		leftFill.fillAmount = 0f;
		rightFill.fillAmount = 0f;
	}

	public void ShowForSkill(PlayerStatsManager.SkillType type, SkillProvider left, SkillProvider right, float duration)
	{
		float skillValue = left.GetSkillValue((int)type);
		float skillValue2 = right.GetSkillValue((int)type);
		float num = 10f;
		if (type == PlayerStatsManager.SkillType.Speed)
		{
			num = 2f;
		}
		float num2 = Mathf.Max(skillValue, skillValue2, num);
		StartShowing(type.ToString(), skillValue / num2, skillValue2 / num2, duration);
	}

	public void ShowForFloat(string name, float left, float right, float minMaxValue, float duration)
	{
		float num = Mathf.Max(left, right, minMaxValue);
		StartShowing(name, left / num, right / num, duration);
	}

	public void StartShowing(string name, float leftValue, float rightValue, float duration)
	{
		nameLabel.cachedGameObject.SetActive(true);
		nameLabel.text = name;
		nameLabel.alpha = 0f;
		nameLabel.cachedTransform.localScale = new Vector3(1f, 2f, 1f);
		TweenAlpha.Begin(nameLabel.cachedGameObject, duration, 1f);
		TweenScale.Begin(nameLabel.cachedGameObject, duration, Vector3.one);
		leftProperty = new Property
		{
			propertyValue = leftValue,
			fillSprite = leftFill
		};
		rightProperty = new Property
		{
			propertyValue = rightValue,
			fillSprite = rightFill
		};
		bool flag = leftValue < rightValue;
		Property property = ((!flag) ? rightProperty : leftProperty);
		Property property2 = ((!flag) ? leftProperty : rightProperty);
		property.fillSprite.color = minColor;
		property2.fillSprite.color = maxColor;
	}

	private void Update()
	{
		if (leftProperty != null && rightProperty != null)
		{
			float delta = RealTime.deltaTime * speed;
			leftProperty.UpdateFillSprite(delta);
			rightProperty.UpdateFillSprite(delta);
		}
	}
}
